//
//  CouponHeaderView.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/19.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "CouponHeaderView.h"

@interface CouponHeaderView ()

@property (nonatomic, weak)UIButton * closeButton;
@property (nonatomic, weak)UILabel * titleLabel;

@end

@implementation CouponHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"优惠券";
    titleLabel.font = [UIFont boldSystemFontOfSize:18 * SCREENH6];
    titleLabel.textColor = ZRBlackColor;
    
    self.titleLabel = titleLabel;
    
    [self addSubview:self.titleLabel];
    
    
    UIButton * closeButton = [UIButton new];

    [closeButton setImage:[UIImage imageNamed:@"cross"] forState:UIControlStateNormal];
    [closeButton addTarget:self action:@selector(clickCloseButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.closeButton = closeButton;
    
    [self addSubview:self.closeButton];
}


- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(13 * SCREENH6);
    }];
    
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.titleLabel);
        make.width.mas_equalTo(16 * SCREENH6);
        make.height.mas_equalTo(16.5 * SCREENH6);
    }];
}

- (void)clickCloseButton{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickCloseButton" object:nil];
}

@end
